package com.indexingsystem.db.mongoDB.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.bson.conversions.Bson;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.indexingsystem.boss.Vo.VideosTableVo;
import com.indexingsystem.boss.Vo.VideosVo;
import com.indexingsystem.boss.entity.AuditLogs;
import com.indexingsystem.boss.entity.DhResourceauditlogs;
import com.indexingsystem.boss.entity.DhTodayStorageInfos;
import com.indexingsystem.boss.entity.ResCategoryRelations;
import com.indexingsystem.boss.entity.ResourceRelations;
import com.indexingsystem.boss.entity.Resources;
import com.indexingsystem.boss.entity.SpecialResourceDatas;
import com.indexingsystem.boss.entity.Videos;
import com.indexingsystem.boss.logback.LogCvt;
import com.indexingsystem.boss.utils.JsonUtils;
import com.indexingsystem.db.mongoDB.MongoManager;
import com.indexingsystem.db.mongoDB.comon.MongoDBUtils;
import com.indexingsystem.db.mongoDB.comon.MongoTableName;
import com.indexingsystem.db.mongoDB.po.VideosResourceMongoVo;
import com.mongodb.BasicDBObject;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.UpdateOptions;

/**
 * 存储videos结构Mongo内存操作实现类
 * 
 * @author Administrator
 * 
 */
public class VideosMongo {

	/**
	 * videos新增mongo
	 * 
	 * @param videosList
	 * @throws Exception
	 */
	public static void addVideos(VideosResourceMongoVo videosResourceMongoVo, String institutionId) throws Exception {
		MongoManager manager = new MongoManager();
		LogCvt.debug( MongoTableName.DH_VIDEOS_LIST + "添加 ------->" + com.alibaba.fastjson.JSON.toJSONString( videosResourceMongoVo, true ) );
		if (null != videosResourceMongoVo) {
			Document mainDocument = new Document();
			mainDocument.put( "_id", videosResourceMongoVo.getResId() );
			mainDocument.put( "resId", videosResourceMongoVo.getResId() );
			mainDocument.put( "resTable", videosResourceMongoVo.getResTable() );
			mainDocument.put( "resTypeId", videosResourceMongoVo.getResTypeId() );
			mainDocument.put( "institutionId", institutionId );

			Document videosDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getVideos() );
			mainDocument.put( "videos", videosDoc );

			Document resourcesDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getResources() );
			mainDocument.put( "resources", resourcesDoc );

			Document resourceauditlogsDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getResourceauditlogs() );
			mainDocument.put( "resourceauditlogs", resourceauditlogsDoc );

			Document auditLogsDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getAuditLogs() );
			mainDocument.put( "auditLogs", auditLogsDoc );

			Document todayStorageInfosDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getTodayStorageInfos() );
			mainDocument.put( "todayStorageInfos", todayStorageInfosDoc );

			List<Document> specialResourceDatasDocList = new ArrayList<Document>();
			if (null != videosResourceMongoVo.getDhSpecialResourceDatasList() && videosResourceMongoVo.getDhSpecialResourceDatasList().size() > 0) {
				for (SpecialResourceDatas specialResourceDatas : videosResourceMongoVo.getDhSpecialResourceDatasList()) {
					Document specialResourceDatasDoc = MongoDBUtils.transform2Doc( specialResourceDatas );
					specialResourceDatasDocList.add( specialResourceDatasDoc );
				}
			}
			mainDocument.put( "dhSpecialResourceDatasList", specialResourceDatasDocList );

			// 资源关系列表
			List<Document> dhResourceRelationsDocList = new ArrayList<Document>();
			if (null != videosResourceMongoVo.getDhResourceRelationsList() && videosResourceMongoVo.getDhResourceRelationsList().size() > 0) {
				for (ResourceRelations resourceRelations : videosResourceMongoVo.getDhResourceRelationsList()) {
					Document resourceRelationsDoc = MongoDBUtils.transform2Doc( resourceRelations );
					dhResourceRelationsDocList.add( resourceRelationsDoc );
				}
			}
			mainDocument.put( "dhResourceRelationsList", dhResourceRelationsDocList );

			// 资源分类关系列表
			List<Document> resCategoryRelationsList = new ArrayList<Document>();
			if (null != videosResourceMongoVo.getResCategoryRelationsList() && videosResourceMongoVo.getResCategoryRelationsList().size() > 0) {
				for (ResCategoryRelations dhResourceCategoryRelations : videosResourceMongoVo.getResCategoryRelationsList()) {
					Document resCategoryRelationsVoDoc = MongoDBUtils.transform2Doc( dhResourceCategoryRelations );
					resCategoryRelationsList.add( resCategoryRelationsVoDoc );
				}
			}
			mainDocument.put( "resCategoryRelationsList", resCategoryRelationsList );

			manager.add( mainDocument, MongoTableName.DH_VIDEOS_LIST );
		}
	}

	public static VideosResourceMongoVo findVideosResourceMongoVoByRedId(String redId, String format, String institutionId) {
		MongoManager manager = new MongoManager();

		LogCvt.debug( MongoTableName.DH_VIDEOS_LIST + "查视频或图片列表 ------->" );
		BasicDBObject basicDBObject = new BasicDBObject();
		basicDBObject.put( "resTable", "Videos" );
		basicDBObject.put( "institutionId", institutionId );

		if (StringUtils.isNotBlank( redId )) {
			basicDBObject.put( "resId", redId );
		}
		if (format.equals( "Videos" )) {
			BasicDBObject not = new BasicDBObject( "$ne", 0 );
			basicDBObject.put( "videos.format", not );
		}
		if (format.equals( "Pictures" )) {
			BasicDBObject not = new BasicDBObject( "$eq", 0 );
			basicDBObject.put( "videos.format", not );
		}
		// 排序条件
		Document sortDocument = new Document();
		sortDocument.put( "resources.publishDate", -1 );
		// 不显示的字段
		Document fetchFields = new Document();
		fetchFields.put( "_id", 0 );
		List<Document> documentsList = manager.queryPages( MongoTableName.DH_VIDEOS_LIST, basicDBObject, sortDocument, fetchFields, 1 );
		VideosResourceMongoVo videosResourceMongoVo = null;
		try {
			if (null != documentsList && documentsList.size() > 0) {

				for (Document document : documentsList) {

					videosResourceMongoVo = new VideosResourceMongoVo();

					String resId = JSON.toJSONString( document.get( "resId" ) );
					videosResourceMongoVo.setResId( resId );

					String resTable = JSON.toJSONString( document.get( "resTable" ) );
					videosResourceMongoVo.setResTable( resTable );

					String resTypeId = JSON.toJSONString( document.get( "resTypeId" ) );
					videosResourceMongoVo.setResTypeId( resTypeId );

					Videos videos = new Videos();
					videos = (Videos) MongoDBUtils.setFieldValue( videos, Document.parse( JsonUtils.toJson( document.get( "videos" ) ) ) );
					if (null != videos) {
						videosResourceMongoVo.setVideos( videos );

					}

					Resources resources = new Resources();
					resources = (Resources) MongoDBUtils.setFieldValue( resources, Document.parse( JsonUtils.toJson( document.get( "resources" ) ) ) );
					if (null != resources) {
						videosResourceMongoVo.setResources( resources );
					}

					DhResourceauditlogs resourceauditlogs = new DhResourceauditlogs();
					resourceauditlogs = (DhResourceauditlogs) MongoDBUtils.setFieldValue( resourceauditlogs,
							Document.parse( JsonUtils.toJson( document.get( "resourceauditlogs" ) ) ) );
					if (null != resourceauditlogs) {
						videosResourceMongoVo.setResourceauditlogs( resourceauditlogs );
					}

					AuditLogs auditLogs = new AuditLogs();
					auditLogs = (AuditLogs) MongoDBUtils.setFieldValue( auditLogs, Document.parse( JsonUtils.toJson( document.get( "auditLogs" ) ) ) );
					if (null != auditLogs) {
						videosResourceMongoVo.setAuditLogs( auditLogs );
					}

					DhTodayStorageInfos todayStorageInfos = new DhTodayStorageInfos();
					todayStorageInfos = (DhTodayStorageInfos) MongoDBUtils.setFieldValue( todayStorageInfos,
							Document.parse( JsonUtils.toJson( document.get( "todayStorageInfos" ) ) ) );
					if (null != todayStorageInfos) {
						videosResourceMongoVo.setTodayStorageInfos( todayStorageInfos );
					}

					List<SpecialResourceDatas> dhSpecialResourceDatasList = new ArrayList<SpecialResourceDatas>();
					dhSpecialResourceDatasList = JSONArray.parseArray( JsonUtils.toJson( document.get( "dhSpecialResourceDatasList" ) ),
							SpecialResourceDatas.class );
					if (null != dhSpecialResourceDatasList && dhSpecialResourceDatasList.size() > 0) {
						videosResourceMongoVo.setDhSpecialResourceDatasList( dhSpecialResourceDatasList );
					}

					List<ResourceRelations> dhResourceRelationsList = new ArrayList<ResourceRelations>();
					dhResourceRelationsList = JSONArray.parseArray( JsonUtils.toJson( document.get( "dhResourceRelationsList" ) ),
							ResourceRelations.class );
					if (null != dhResourceRelationsList && dhResourceRelationsList.size() > 0) {
						videosResourceMongoVo.setDhResourceRelationsList( dhResourceRelationsList );
					}

					List<ResCategoryRelations> resCategoryRelationsList = new ArrayList<ResCategoryRelations>();
					resCategoryRelationsList = JSONArray.parseArray( JsonUtils.toJson( document.get( "resCategoryRelationsList" ) ),
							ResCategoryRelations.class );
					if (null != resCategoryRelationsList && resCategoryRelationsList.size() > 0) {
						videosResourceMongoVo.setResCategoryRelationsList( resCategoryRelationsList );
					}

				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}

		LogCvt.debug( "查询 videosResourceMongoVo 结果:" + JSON.toJSONString( videosResourceMongoVo, true ) );
		return videosResourceMongoVo;
	}

	/**
	 * 通过视频资源idlist 和机构id获取视频列表资源.
	 * 
	 * @param redIdList
	 * @param format
	 * @param institutionId
	 * @return
	 */
	public static List<VideosResourceMongoVo> findVideosResourceMongoVoListByRedId(List<String> redIdList, String institutionId) {
		MongoManager manager = new MongoManager();

		LogCvt.debug( MongoTableName.DH_VIDEOS_LIST + "查视频或图片列表 ------->" );
		BasicDBObject basicDBObject = new BasicDBObject();
		basicDBObject.put( "resTable", "Videos" );
		basicDBObject.put( "institutionId", institutionId );

		if (null != redIdList && redIdList.size() > 0) {
			basicDBObject.put( "resId", new BasicDBObject( "$in", redIdList ) );
		}
		// 排序条件
		Document sortDocument = new Document();
		sortDocument.put( "resources.publishDate", -1 );
		// 不显示的字段
		Document fetchFields = new Document();
		fetchFields.put( "_id", 0 );
		List<Document> documentsList = manager.queryPages( MongoTableName.DH_VIDEOS_LIST, basicDBObject, sortDocument, fetchFields, 1 );
		List<VideosResourceMongoVo> videosResourceMongoVoList = null;
		try {
			if (null != documentsList && documentsList.size() > 0) {
				videosResourceMongoVoList = new ArrayList<VideosResourceMongoVo>();
				for (Document document : documentsList) {
					VideosResourceMongoVo videosResourceMongoVo = new VideosResourceMongoVo();
					String resId = JSON.toJSONString( document.get( "resId" ) );
					videosResourceMongoVo.setResId( resId );

					String resTable = JSON.toJSONString( document.get( "resTable" ) );
					videosResourceMongoVo.setResTable( resTable );

					String resTypeId = JSON.toJSONString( document.get( "resTypeId" ) );
					videosResourceMongoVo.setResTypeId( resTypeId );

					Videos videos = new Videos();
					videos = (Videos) MongoDBUtils.setFieldValue( videos, Document.parse( JsonUtils.toJson( document.get( "videos" ) ) ) );
					if (null != videos) {
						videosResourceMongoVo.setVideos( videos );

					}

					Resources resources = new Resources();
					resources = (Resources) MongoDBUtils.setFieldValue( resources, Document.parse( JsonUtils.toJson( document.get( "resources" ) ) ) );
					if (null != resources) {
						videosResourceMongoVo.setResources( resources );
					}

					DhResourceauditlogs resourceauditlogs = new DhResourceauditlogs();
					resourceauditlogs = (DhResourceauditlogs) MongoDBUtils.setFieldValue( resourceauditlogs,
							Document.parse( JsonUtils.toJson( document.get( "resourceauditlogs" ) ) ) );
					if (null != resourceauditlogs) {
						videosResourceMongoVo.setResourceauditlogs( resourceauditlogs );
					}

					AuditLogs auditLogs = new AuditLogs();
					auditLogs = (AuditLogs) MongoDBUtils.setFieldValue( auditLogs, Document.parse( JsonUtils.toJson( document.get( "auditLogs" ) ) ) );
					if (null != auditLogs) {
						videosResourceMongoVo.setAuditLogs( auditLogs );
					}

					DhTodayStorageInfos todayStorageInfos = new DhTodayStorageInfos();
					todayStorageInfos = (DhTodayStorageInfos) MongoDBUtils.setFieldValue( todayStorageInfos,
							Document.parse( JsonUtils.toJson( document.get( "todayStorageInfos" ) ) ) );
					if (null != todayStorageInfos) {
						videosResourceMongoVo.setTodayStorageInfos( todayStorageInfos );
					}

					List<SpecialResourceDatas> dhSpecialResourceDatasList = new ArrayList<SpecialResourceDatas>();
					dhSpecialResourceDatasList = JSONArray.parseArray( JsonUtils.toJson( document.get( "dhSpecialResourceDatasList" ) ),
							SpecialResourceDatas.class );
					if (null != dhSpecialResourceDatasList && dhSpecialResourceDatasList.size() > 0) {
						videosResourceMongoVo.setDhSpecialResourceDatasList( dhSpecialResourceDatasList );
					}

					List<ResourceRelations> dhResourceRelationsList = new ArrayList<ResourceRelations>();
					dhResourceRelationsList = JSONArray.parseArray( JsonUtils.toJson( document.get( "dhResourceRelationsList" ) ),
							ResourceRelations.class );
					if (null != dhResourceRelationsList && dhResourceRelationsList.size() > 0) {
						videosResourceMongoVo.setDhResourceRelationsList( dhResourceRelationsList );
					}

					List<ResCategoryRelations> resCategoryRelationsList = new ArrayList<ResCategoryRelations>();
					resCategoryRelationsList = JSONArray.parseArray( JsonUtils.toJson( document.get( "resCategoryRelationsList" ) ),
							ResCategoryRelations.class );
					if (null != resCategoryRelationsList && resCategoryRelationsList.size() > 0) {
						videosResourceMongoVo.setResCategoryRelationsList( resCategoryRelationsList );
					}

					if (!videosResourceMongoVoList.contains( videosResourceMongoVo )) {
						videosResourceMongoVoList.add( videosResourceMongoVo );
					}

				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
			LogCvt.error( "查询 videosResourceMongoVo 结果:" + ex.getMessage() );
		}

		LogCvt.debug( "查询 videosResourceMongoVo 结果:" + JSON.toJSONString( videosResourceMongoVoList, true ) );
		return videosResourceMongoVoList;
	}

	/**
	 * 入库管理单一修改video资源mongo修改.
	 * 
	 * @param videosListPo
	 * @throws Exception
	 */
	public static void updateVideosByVideosReqVo(VideosResourceMongoVo videosResourceMongoVo, String institutionId) throws Exception {
		MongoManager manager = new MongoManager();
		LogCvt.debug( MongoTableName.DH_VIDEOS_LIST + "修改 ------->" + com.alibaba.fastjson.JSON.toJSONString( videosResourceMongoVo, true ) );
		if (null != videosResourceMongoVo) {
			Document mainDocument = new Document();
			mainDocument.put( "resId", videosResourceMongoVo.getResId() );
			mainDocument.put( "resTypeId", videosResourceMongoVo.getResTypeId() );
			mainDocument.put( "resTable", videosResourceMongoVo.getResTable() );
			mainDocument.put( "institutionId", institutionId );

			Document videosDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getVideos() );
			mainDocument.put( "videos", videosDoc );

			Document resourcesDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getResources() );
			mainDocument.put( "resources", resourcesDoc );

			Document resourceauditlogsDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getResourceauditlogs() );
			mainDocument.put( "resourceauditlogs", resourceauditlogsDoc );

			Document auditLogsDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getAuditLogs() );
			mainDocument.put( "auditLogs", auditLogsDoc );

			Document todayStorageInfosDoc = MongoDBUtils.transform2Doc( videosResourceMongoVo.getTodayStorageInfos() );
			mainDocument.put( "todayStorageInfos", todayStorageInfosDoc );

			List<Document> specialResourceDatasDocList = new ArrayList<Document>();
			if (null != videosResourceMongoVo.getDhSpecialResourceDatasList() && videosResourceMongoVo.getDhSpecialResourceDatasList().size() > 0) {
				for (SpecialResourceDatas specialResourceDatas : videosResourceMongoVo.getDhSpecialResourceDatasList()) {
					Document specialResourceDatasDoc = MongoDBUtils.transform2Doc( specialResourceDatas );
					specialResourceDatasDocList.add( specialResourceDatasDoc );
				}
			}
			mainDocument.put( "dhSpecialResourceDatasList", specialResourceDatasDocList );

			List<Document> dhResourceRelationsDocList = new ArrayList<Document>();
			if (null != videosResourceMongoVo.getDhResourceRelationsList() && videosResourceMongoVo.getDhResourceRelationsList().size() > 0) {
				for (ResourceRelations resourceRelations : videosResourceMongoVo.getDhResourceRelationsList()) {
					Document resourceRelationsDoc = MongoDBUtils.transform2Doc( resourceRelations );
					dhResourceRelationsDocList.add( resourceRelationsDoc );
				}
			}
			mainDocument.put( "dhResourceRelationsList", dhResourceRelationsDocList );
			UpdateOptions options = new UpdateOptions().upsert( true );
			Bson bson = Filters.and( Filters.eq( "resId", videosResourceMongoVo.getResId() ), Filters.eq( "institutionId", institutionId ) );
			Document doc = new Document( "$set", mainDocument );
			manager.updateOne( bson, doc, options, MongoTableName.DH_VIDEOS_LIST );
		}
	}

	/**
	 * 批量删除更新mongodb
	 * 
	 * @param map
	 * @return
	 */
	public static void deleteVideosByIds(List<String> resIdList, String institutionId) {
		MongoManager manager = new MongoManager();
		Bson bson = Filters.and( Filters.in( "resId", resIdList ), Filters.eq( "institutionId", institutionId ) );
		manager.deleteAll( bson, MongoTableName.DH_VIDEOS_LIST );
	}

	/**
	 * 返回video列表
	 * 
	 * @param map
	 * @return
	 */
	public static List<VideosTableVo> findVideosByPage(VideosVo videosVo, String format, String institutionId) {
		MongoManager manager = new MongoManager();
		List<VideosTableVo> videoTableVoList = null;
		LogCvt.debug( MongoTableName.DH_VIDEOS_LIST + "查询" + format + "列表 ------->" );
		BasicDBObject basicDBObject = new BasicDBObject();
		basicDBObject.put( "institutionId", institutionId );

		// 时间查询
		if (videosVo.getStartPublishDate() != null && !videosVo.getStartPublishDate().equals( "" )) {

			BasicDBObject gt = new BasicDBObject( "$gte", videosVo.getStartPublishDate() );
			basicDBObject.put( "resources.publishDate", gt );
		}
		if (videosVo.getEndPublishDate() != null && !videosVo.getEndPublishDate().equals( "" )) {
			BasicDBObject lt = new BasicDBObject( "$lte", videosVo.getEndPublishDate() );
			basicDBObject.put( "resources.publishDate", lt );
		}
		if (StringUtils.isNotBlank( videosVo.getTerminalCode() )) {
			basicDBObject.put( "dhSpecialResourceDatasList.terminalCode", videosVo.getTerminalCode() );
		}
		if (null != videosVo.getStatus()) {
			basicDBObject.put( "resources.status", videosVo.getStatus() );
		}
		if (StringUtils.isNotBlank( videosVo.getQueryCriteria() )) {
			Pattern pattern = Pattern.compile( ".*" + videosVo.getQueryCriteria() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "resources.resName", pattern );
		}
		if (format.equals( "Videos" )) {
			BasicDBObject not = new BasicDBObject( "$ne", 0 );
			basicDBObject.put( "videos.format", not );
		}
		if (format.equals( "Pictures" )) {
			BasicDBObject not = new BasicDBObject( "$eq", 0 );
			basicDBObject.put( "videos.format", not );
		}

		// 排序条件
		Document sortDocument = new Document();
		sortDocument.put( "resources.publishDate", -1 );
		sortDocument.put( "resources.resName", -1 );

		// 不显示的字段
		Document fetchFields = new Document();
		fetchFields.put( "_id", 0 );
		fetchFields.put( "videos", 1 );
		fetchFields.put( "resources", 1 );
		/* fetchFields.put( "dhSpecialResourceDatasList", 0 ); */

		List<Document> documentsList = manager.queryPages( MongoTableName.DH_VIDEOS_LIST, basicDBObject, sortDocument, fetchFields,
				videosVo.getPageNumber(), videosVo.getPageSize() );
		try {
			if (null != documentsList && documentsList.size() > 0) {
				videoTableVoList = new ArrayList<VideosTableVo>();
				for (Document document : documentsList) {
					VideosTableVo videosTableVo = new VideosTableVo();
					Videos videos = new Videos();
					videos = (Videos) MongoDBUtils.setFieldValue( videos, Document.parse( JsonUtils.toJson( document.get( "videos" ) ) ) );
					if (null != videos) {
						videosTableVo.setVideoSize( videos.getVideoSize() );
						videosTableVo.setVideoLength( videos.getVideoLength() );
						videosTableVo.setFileType( videos.getFileType() );
						videosTableVo.setVideoType( (videos.getVideoType()).longValue() );
					}
					Resources resources = new Resources();
					resources = (Resources) MongoDBUtils.setFieldValue( resources, Document.parse( JsonUtils.toJson( document.get( "resources" ) ) ) );
					if (null != resources) {
						videosTableVo.setThumbnail( resources.getThumbnail() );
						videosTableVo.setKeyword( resources.getKeyword() );
						videosTableVo.setPublishDate( resources.getPublishDate() );
						videosTableVo.setResName( resources.getResName() );
						videosTableVo.setStatus( resources.getStatus() );
						videosTableVo.setResId( resources.getResId() );
					}
					if (!videoTableVoList.contains( videosTableVo )) {
						videoTableVoList.add( videosTableVo );
					}
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		LogCvt.debug( "查询 videoTableVoList 结果:" + JSON.toJSONString( videoTableVoList, true ) );
		return videoTableVoList;
	}

	/**
	 * 返回vidos列表总数量
	 * 
	 * @param map
	 * @return
	 */
	public static Integer findVideosMaxCount(VideosVo videosVo, String format, String institutionId) {
		MongoManager manager = new MongoManager();
		LogCvt.debug( MongoTableName.DH_VIDEOS_LIST + "查询" + format + "列表总数量 ------->" );
		BasicDBObject basicDBObject = new BasicDBObject();
		basicDBObject.put( "institutionId", institutionId );

		// 时间查询
		if (videosVo.getStartPublishDate() != null && !videosVo.getStartPublishDate().equals( "" )) {
			basicDBObject.put( "resources.publishDate", new BasicDBObject().put( "$gte", videosVo.getStartPublishDate() ) );
			BasicDBObject gt = new BasicDBObject( "$gte", videosVo.getStartPublishDate() );
			basicDBObject.put( "resources.publishDate", gt );
		}
		if (videosVo.getEndPublishDate() != null && !videosVo.getEndPublishDate().equals( "" )) {
			BasicDBObject lt = new BasicDBObject( "$lte", videosVo.getEndPublishDate() );
			basicDBObject.put( "resources.publishDate", lt );
		}
		if (StringUtils.isNotBlank( videosVo.getTerminalCode() )) {
			basicDBObject.put( "dhSpecialResourceDatasList.terminalCode", videosVo.getTerminalCode() );
		}
		if (null != videosVo.getStatus()) {
			basicDBObject.put( "resources.status", videosVo.getStatus() );
		}
		if (StringUtils.isNotBlank( videosVo.getQueryCriteria() )) {
			Pattern pattern = Pattern.compile( ".*" + videosVo.getQueryCriteria() + ".*", Pattern.CASE_INSENSITIVE );
			basicDBObject.put( "resources.resName", pattern );
		}
		if (format.equals( "Videos" )) {
			BasicDBObject not = new BasicDBObject( "$ne", 0 );
			basicDBObject.put( "videos.format", not );
		}
		if (format.equals( "Pictures" )) {
			BasicDBObject not = new BasicDBObject( "$eq", 0 );
			basicDBObject.put( "videos.format", not );
		}

		// 不显示的字段
		Document fetchFields = new Document();
		fetchFields.put( "_id", 0 );
		fetchFields.put( "resId", 1 );
		Integer maxCount = manager.queryAggregateListMaxCount( basicDBObject, MongoTableName.DH_VIDEOS_LIST );

		LogCvt.debug( "查询 findVideosMaxCount 结果:" + maxCount );
		return maxCount;
	}

	public static void transMap2Bean2(Map<String, Object> map, Object obj) {
		if (map == null || obj == null) {
			return;
		}
		try {
			BeanUtils.populate( obj, map );
		} catch (Exception e) {
			System.out.println( "transMap2Bean2 Error " + e );
		}

	}
}